package common_config

import (
	_ "embed"
	"gitee.com/zaper/service-center/util"
	"gitee.com/zaper/service-config-client/client/listen/flush"
)

//go:embed config/common_config.properties
var config string

type CommonConfigModel struct {
	properties *util.Properties
}

func NewCommonConfigModel() *CommonConfigModel {
	pies, err := util.ParseStringToProperties(config)
	if err != nil {
		println("config read fail")
		return nil
	}
	return &CommonConfigModel{
		properties: pies,
	}
}

func (commonConfigModel *CommonConfigModel) GetDBFlushConfig() *flush.FlushModel {
	return &flush.FlushModel{
		FileName: commonConfigModel.properties.Data["DBConfigFile"],
		FilePath: commonConfigModel.properties.Data["DBConfigPath"],
	}
}

func (commonConfigModel *CommonConfigModel) RedisFlushConfig() *flush.FlushModel {
	return &flush.FlushModel{
		FileName: commonConfigModel.properties.Data["RedisConfigFile"],
		FilePath: commonConfigModel.properties.Data["RedisConfigPath"],
	}
}

func (commonConfigModel *CommonConfigModel) OtherFlushConfig() *flush.FlushModel {
	return &flush.FlushModel{
		FileName: commonConfigModel.properties.Data["OtherConfigFile"],
		FilePath: commonConfigModel.properties.Data["OtherConfigPath"],
	}
}
